Skip to content

fix(validation): remove polynomial ReDoS in email regexes#2688

Merged
os-zhuang merged 2 commits into
mainfrom
claude/redos-email-regex-validators-vlx7ay
Jul 8, 2026
Merged

fix(validation): remove polynomial ReDoS in email regexes#2688
os-zhuang merged 2 commits into
mainfrom
claude/redos-email-regex-validators-vlx7ay

Conversation

@os-zhuang

Copy link
Copy Markdown
Contributor

Summary

Fixes the CodeQL polynomial regex (ReDoS) finding (#2681) in the email
validators.

All three copies of the email pattern used:

/^[^\s@]+@[^\s@]+\.[^\s@]+$/

Because the literal . is itself a member of [^\s@], the quantifiers on
either side of \. overlap, so the engine backtracks polynomially on
adversarial input (a long run of domain-ish characters with no valid
terminator).

The domain part is rewritten so labels exclude .:

/^[^\s@]+@[^\s@.]+(?:\.[^\s@.]+)+$/

Now the quantifiers around each dot no longer overlap and matching is
linear. Semantics are preserved for valid addresses (local part @
dotted domain; multi-label domains like a@b.co.uk still accepted). The
only behavioural change is that consecutive dots — an empty, invalid label
such as a@b..c — are now correctly rejected.

Changes

  • packages/objectql/src/validation/record-validator.tsEMAIL_RE
  • packages/objectql/src/validation/rule-validator.tsEMAIL_RE
  • packages/plugins/plugin-email/src/email-service.tsEMAIL_REGEX
    (same pattern, same vulnerability — fixed for consistency)
  • packages/objectql/src/validation/rule-validator.test.ts — new tests
    for multi-label domains, empty-label rejection, and a linear-time
    (no-ReDoS) adversarial-input guard.

Verification

  • objectql validator suites: 48 passing (incl. new tests)
  • plugin-email suites: 61 passing
  • objectql builds cleanly (ESM/CJS/DTS)
  • Direct timing check: the new pattern runs linearly on 50k+ adversarial
    input where the old one backtracks.

Note: content/docs/protocol/objectui/concept.mdx shows the old pattern as
an illustrative example only (docs, not shipped code) and is intentionally
left unchanged. service-messaging/recipient-resolver.ts already uses a
hand-rolled linear check and documents this exact concern.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CajRFHqgkDMjV6xxDKbPec


Generated by Claude Code

The email validators used `/^[^\s@]+@[^\s@]+\.[^\s@]+$/`. Because the
literal `.` is also a member of `[^\s@]`, the quantifiers on either side
of `\.` overlap, so the pattern backtracks polynomially on adversarial
input (CodeQL polynomial-redos, #2681).

Rewrite the domain part as `[^\s@.]+(?:\.[^\s@.]+)+` so labels exclude
`.`; the quantifiers around each dot no longer overlap and matching is
linear. Semantics are preserved for valid addresses (local `@` dotted
domain, multi-label domains still accepted); consecutive dots — an empty,
invalid label — are now correctly rejected.

Applied to all three copies of the pattern:
- packages/objectql/src/validation/record-validator.ts
- packages/objectql/src/validation/rule-validator.ts
- packages/plugins/plugin-email/src/email-service.ts

Add rule-validator tests covering multi-label domains, empty-label
rejection, and a linear-time (no-ReDoS) adversarial-input guard.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CajRFHqgkDMjV6xxDKbPec
@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Ready Ready Preview, Comment Jul 8, 2026 11:02am

Request Review

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 2 package(s): @objectstack/objectql, @objectstack/plugin-email.

13 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:

  • content/docs/concepts/metadata-lifecycle.mdx (via @objectstack/objectql)
  • content/docs/data-modeling/formulas.mdx (via packages/objectql)
  • content/docs/deployment/migration-from-objectql.mdx (via @objectstack/objectql)
  • content/docs/deployment/vercel.mdx (via @objectstack/objectql)
  • content/docs/kernel/services-checklist.mdx (via @objectstack/objectql)
  • content/docs/kernel/services.mdx (via @objectstack/objectql)
  • content/docs/permissions/authentication.mdx (via @objectstack/objectql)
  • content/docs/plugins/index.mdx (via @objectstack/objectql)
  • content/docs/plugins/packages.mdx (via @objectstack/objectql, @objectstack/plugin-email)
  • content/docs/protocol/objectos/index.mdx (via @objectstack/objectql)
  • content/docs/protocol/objectql/state-machine.mdx (via @objectstack/objectql)
  • content/docs/releases/implementation-status.mdx (via @objectstack/objectql)
  • content/docs/releases/v9.mdx (via @objectstack/objectql)

Advisory only. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs origin/main → pass the list as args.docs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CajRFHqgkDMjV6xxDKbPec
@github-actions github-actions Bot added documentation Improvements or additions to documentation tooling labels Jul 8, 2026
@os-zhuang os-zhuang marked this pull request as ready for review July 8, 2026 11:09
@os-zhuang os-zhuang merged commit a1766fe into main Jul 8, 2026
16 checks passed
@os-zhuang os-zhuang deleted the claude/redos-email-regex-validators-vlx7ay branch July 8, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/s tests tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants